const Service = require('egg').Service;

class CollectionService extends Service {
    async getList(conditions, page, limit) {
        const { app, ctx } = this;
        const pageOffset = ctx.helper.toInt((page - 1) * limit);
        const pageLimit = ctx.helper.toInt(limit);
        const list = await ctx.model.Collection.findAndCountAll({
            include:[{
                model: app.model.User,
                attributes:['username','avatar']
            }],
            where: conditions,
            limit: pageLimit,
            offset: pageOffset
        })
        return list;
    }
}

module.exports = CollectionService;